package com.greenleaf.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.greenleaf.entity.SearchCon;
import com.greenleaf.entity.SlideShow;
import com.greenleaf.service.SlideShowService;
@Controller
@RequestMapping("/slideShow")
public class SlideShowController {
	
		@Resource
		private SlideShowService slideShowService;

		@RequestMapping("/get")
		@ResponseBody
	//http://localhost:8080/Greenleaf/slideShow/get
		public Object getAllSlideShow(SearchCon searchCon,HttpServletRequest request) {
			List<SlideShow> slideShow = slideShowService.getAllSlideShow(searchCon);
			Map<String, Object> map = new HashMap<String, Object>();
			ServletContext app=request.getServletContext();
			app.setAttribute("slideShow", slideShow);//存放论坛信息
			map.put("code", "0");
			map.put("msg", "0");
			map.put("count", slideShowService.getTotalSlideShow(searchCon));
			map.put("data", slideShow);
			return map;
		}
		@RequestMapping("/add")
		@ResponseBody
	//http://localhost:8080/Greenleaf/slideShow/add
		public Object addSlideShow(SlideShow slideShow) {
			int r = slideShowService.addSlideShow(slideShow);
			return r==1?true:false;
		}
		@RequestMapping("/update")
		@ResponseBody
		//http://localhost:8080/Greenleaf/slideShow/update
		public Object updateSlideShow(SlideShow slideShow) {
			int r = slideShowService.updateSlideShow(slideShow);
			return r==1?true:false;
		}
		@RequestMapping("/del")
		@ResponseBody
		//http://localhost:8080/Greenleaf/slideShow/del
		public Object delSlideShow(Integer sdId) {
			int r = slideShowService.delSlideShow(sdId);
			return r==1?true:false;
		}
		@RequestMapping("/dels")
		@ResponseBody
		//http://localhost:8080/Greenleaf/slideShow/dels
		public Object delProducts(String ids) {
			System.out.println(ids);
			System.out.println(ids);
			System.out.println(ids);
			System.out.println(ids);
			String[] listIds = ids.split(",");
			List<Integer> list = new ArrayList<Integer>();
			for (String listStr : listIds) {
				list.add(Integer.parseInt(listStr));
			}
			int r = slideShowService.delSlideShows(list);
			return r!=0?true:false;
		}
	}

